package com.hxm.demo.test1;

import cn.hutool.core.io.FileUtil;
import cn.hutool.http.HttpUtil;

/**
 * description: add a description
 *
 * @author huangxiaoming
 * @version 1.0.0
 * @date 2022/11/01 17:36:29
 */
public class Test {

//    public static void main(String[] args) {
////        ExcelReader reader = ExcelUtil.getReader("D:\\My Documents\\Downloads\\e26dccdd-83c6-44b8-8cb3-974a70a59b1f.xlsx");
////        List<Map<String,Object>> all = reader.readAll();
////        System.out.println(all);
//
//        String fileUrl = "https://dudian-oss-test.oss-cn-shenzhen.aliyuncs.com/dlabel/1/dbfile/24613d17-b99b-4090-bd29-648e4ef6040d.xls";
//
////将文件下载后保存在E盘，返回结果为下载文件大小
//        long size = HttpUtil.downloadFile(fileUrl, FileUtil.file("D:\\My Documents\\Downloads"));
//        System.out.println("Download size: " + size);
//    }


    public static byte findPaeth1(final int left, final int top, final int lt) {
        final int p = left + top - lt;
        final int pa = p >= left ? p - left : left - p;
        final int pb = p >= top ? p - top : top - p;
        final int pc = p >= lt ? p - lt : lt - p;
        if (pa <= pb && pa <= pc)
            return (byte) (left & 0XFF);
        else if (pb <= pc)
            return (byte) (top & 0XFF);
        else
            return (byte) (lt & 0XFF);
    }

    public static byte findPaeth2(byte left, byte top, byte lt) {
        int p = left + top - lt;
        int pa = Math.abs(p - left);
        int pb = Math.abs(p - top);
        int pc = Math.abs(p - lt);
        byte ret = left;
        if (pa <= pb && pa <= pc) {
            ret = left;
        } else if (pb <= pc) {
            ret = top;
        } else {
            ret = lt;
        }
        return ret;
    }

    public static void main(String[] args) {
        int a = 0, b = 254, c = 255;
        byte d = 0, e = (byte) 254, f = (byte) 255;
        System.out.println(findPaeth1(a, b, c));
        System.out.println(findPaeth2(d, e, f));
    }
}
